home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9149 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  57 lines

  1. Path: rap.SanDiegoCA.ATTGIS.COM!news
  2. From: borisb@sd.znet.com (Boris Burtin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Array of multiple types
  5. Date: Wed, 28 Feb 1996 22:58:34 GMT
  6. Organization: Lunapark Studios
  7. Message-ID: <4h2mm0$50l@rap.SanDiegoCA.ATTGIS.COM>
  8. NNTP-Posting-Host: borisbpc.sandiegoca.attgis.com
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. Hi,
  12.  
  13. I'd like to create a query class, which runs a query via ODBC API
  14. calls and stores the results in a 2D array.  The trouble I'm having is
  15. with the "storing results" part.
  16.  
  17. Columns returned from a query can be composed of several types--mainly
  18. string, integer, float and date.  So if the user does
  19.  
  20.         SELECT Name, ID, DateOfHire
  21.         FROM Employees
  22.  
  23. The results will come back as a [3][n] array with the types of string,
  24. integer, and date for each respective column.  The array must be
  25. created dynamically, and store each element in its native type.
  26.  
  27. Does anyone have an idea about how I could do this?  The cleanest
  28. solution I came up with is to derive each data type from a base class:
  29.  
  30. class Cell
  31. {
  32. public:
  33.     virtual int GetInt();
  34.     virtual string GetString();
  35.     // etc.
  36. }
  37.  
  38. class IntCell : Cell
  39. {
  40. private:
  41.     int data;
  42. public:
  43.     int GetInt() { return data; }
  44. }
  45.  
  46. The query results class would then contain a 2D array of Cells.  This
  47. approach should work, but it doesn't seem very effective to come up
  48. with a whole new data type that only stores an integer.
  49.  
  50. Does someone have a better plan?  Templates maybe?
  51.  
  52. Thanks,
  53.  
  54. Boris
  55.  
  56.  
  57.